﻿#region Using directives
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using webapp4U.DAL;
using System.Data;
#endregion

/// <summary>
/// Summary description for ShoppingCart
/// </summary>
/// 

namespace webapp4U.BOL
{
    public class ShoppingCart
    {
        #region Member Variables
        
        private DateTime _addedDate;
        
        private String _itemkey;

        private String _description;

        private String _imageUrl;
                
        private float _unitPrice;

        private Int32 _quantity;

        private Double _subtotal;

        #endregion

        #region Public Properties       

        public DateTime AddedDate
        {
            get { return _addedDate; }
            set { _addedDate = value; }
        }     
        
        public String ItemKey
        {
            get { return _itemkey; }
            set { _itemkey = value; }
        }

        public String Description
        {
            get { return _description; }
            set { _description = value; }
        }

        public String ImageUrl
        {
            get { return _imageUrl; }
            set { _imageUrl = value; }
        }

        public float UnitPrice
        {
            get { return _unitPrice; }
            set { _unitPrice = value; }
        }       
        
        public Int32 Quantity
        {
            get { return _quantity; }
            set { _quantity = value; }
        }

        public Double Subtotal
        {
            get { return _subtotal; }
            set { _subtotal = value; }
        }

        #endregion

        public static Double GetTotalShoppingCart(List<ShoppingCart> ShopCart)
        {
            double Total = 0;
            foreach (ShoppingCart shop in ShopCart)
            {
                Total += shop.Subtotal;
            }
            return Total;
        }

        public static List<ShoppingCart> AddItemToShoppingCart(List<ShoppingCart> ShopCart, ShoppingCart Shop)
        {
            bool flag = true;
            foreach (ShoppingCart Item in ShopCart)
            {
                if (Item.ItemKey == Shop.ItemKey)
                {
                    Item.Quantity = Item.Quantity + Shop.Quantity;
                    Item.Subtotal = Item.Quantity * Item.UnitPrice;
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                ShopCart.Add(Shop);                
            }
            return ShopCart;
        }

        // Procced Order
        public static DataTable dtListProvince(ref string error)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.dtListProvince(ref error);
        }

        public static DataTable dtListTownByProvinceCode(ref string error, string ProvinceCode)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.dtListTownByProvinceCode(ref error, ProvinceCode);
        }

        public static DataTable FindCustomerByPhoneOrIdNo(ref string error, string PhoneOrIdNo)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.FindCustomerByPhoneOrIdNo(ref error, PhoneOrIdNo);
        }
        public static DataTable GetOrderTempByCustomerKey(ref string error, string CustommerKey)
        {
             ShoppingCartDAL db = new ShoppingCartDAL();
             return db.GetOrderTempByCustomerKey(ref error, CustommerKey);
        }
        public static List<ShoppingCart> DetailOrderTemp(string OrderId, ref string error)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetDetailOrderTemp(OrderId, ref error);
        }

        public static List<ShoppingCart> GetItemStartKit(ref string error)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetItemStartKit(ref error);
        }
        public static string GetCustomerKeyNew(ref string error)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetCustomerKeyNew(ref error);
        }
        public static string GetAndHoleOrderCode(ref string error)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetAndHoleOrderCode(ref error);
        }
        public static string GetSalesp_key_BASupport(ref string error, string IDNo_CMND, string Phone, string ProvinceID, string TownID)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetSalesp_key_BASupport(ref error, IDNo_CMND, Phone, ProvinceID, TownID);
        }
        public static string GetSiteCodeBySalesp_key(ref string error, string SalespKey)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetSiteCodeBySalesp_key(ref error, SalespKey);
        }

        public static string GetPhoneNumberBA_BySalesp_key(ref string error, string SalespKey)
        { 
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.GetPhoneNumberBA_BySalesp_key(ref error, SalespKey);
        }
        public static bool SendSMS(ref string error, string Phone, string OrderCode)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.SendSMS(ref error, Phone, OrderCode);
        }

        public static bool InsertOrder(ref string error, string Sitecode, string OrderCode, string salesp_key, string UserName, float TongHoaDon,
            string NgayHD, DateTime DateTimeNow, int so, int StattusOrder, string PaymentMethodsID, string ModeOfDeliveryID, string Customer_key)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.InsertOrder(ref error, Sitecode, OrderCode, salesp_key, UserName, TongHoaDon, NgayHD, DateTimeNow, so, StattusOrder,
                PaymentMethodsID, ModeOfDeliveryID, Customer_key);
        }

        public static bool InsertOrderDetail(ref string error, string Sitecode, string MaHD, DateTime DateTimeNow, string UserName, string NgayHD, string MaHang, string TenHang, string LoaiDong, float SoLuong, float Gia, int SoTT)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.InsertOrderDetail(ref error, Sitecode, MaHD, DateTimeNow, UserName, NgayHD, MaHang, TenHang, LoaiDong, SoLuong, Gia, SoTT);
        }

        public static bool InsertCustomerNotRegistry(ref string error, string CustomerKey, string CustomerName, string Address, string Phone,
            string ProvinceCode, string TownCode, string Recdate, string IDCardNo, string SalespKey, string SiteCode)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.InsertCustomerNotRegistry(ref error, CustomerKey, CustomerName, Address, Phone, ProvinceCode, TownCode, Recdate, IDCardNo, SalespKey, SiteCode);
        }

        public static bool DeleteOrderAndOrderDetailOnlineTamGiu(ref string error, string MaHD)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.DeleteOrderAndOrderDetailOnlineTamGiu(ref error, MaHD);
        }

        public static bool DeleteCustomer(ref string error, string CustomerKey)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.DeleteCustomer(ref error, CustomerKey);
        }

        public static bool CheckFirstOrderBySalespKey(ref string error, string SalespKey)
        {
            ShoppingCartDAL db = new ShoppingCartDAL();
            return db.CheckFirstOrderBySalespKey(ref error, SalespKey);
        }
    }
}